from selenium.webdriver.common.by import By
from common.GetLoc import BasePageData


class Basepage:
    base_url = BasePageData().get_base_url()
    loc_recruitManage = (By.XPATH, BasePageData().get_loc_recruitManage())
    loc_currentTask = (By.XPATH, BasePageData().get_loc_currentTask())
    loc_employeeManage = (By.XPATH, BasePageData().get_loc_employeeManage())
    loc_systemManage = (By.XPATH, BasePageData().get_loc_systemManage())
    loc_statistics = (By.XPATH, BasePageData().get_loc_statistics())

    def __init__(self, browser):
        self.driver = browser
        self.driver.get(self.base_url)
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

    def find_ele(self, location):
        return self.driver.find_element(*location)

    def find_eles(self, locations):
        return self.driver.find_elements(*locations)

    def change_window(self, num):
        all_handles = self.driver.window_handles
        return self.driver.switch_to.window(all_handles[num - 1])

    def close_window(self):
        self.driver.close()
